<?php
namespace Home\Controller;

use Think\Controller;

class StaticController extends CommonController{

    public function index(){
     $user_auth = session('USER_AUTH');
     $this->assign('user',$user_auth);
     $parent = I('param.parent_bank');
     $this->assign('parent',$parent);
     $child = I('param.child_bank');
     $this->assign('child',$child);
     $send_start = I('param.send_start');
     $this->assign('send_start',$send_start);
     $send_end = I('param.send_end');
     $this->assign('send_end',$send_end);
     $money_start = I('param.money_start');
     $this->assign('money_start',$money_start);
     $money_end = I('param.money_end');
     $this->assign('money_end',$money_end);
     $market = I('param.market');
     $this->assign('market',$market);
     $sign = I('param.sign');
     $this->assign('sign',$sign);
     $place = I('param.place');
     $this->assign('place',$place);
     $supervise = I('param.supervise');
     $this->assign('supervise',$supervise);
     $send_start = timeStrop($send_start);
     $send_end = timeStrop($send_end);
     $money_start = timeStrop($money_start);
     $money_end = timeStrop($money_end);
      if($_GET['p']==''){
        $p='1';
    }else{
        $p=$_GET['p'];
    }
    if($user_auth['roleid']==3){
	    if(!empty($user_auth['banks'])){
	        $data['bank_id'] = array('IN',$user_auth['banks']);
	    }
  	}
  	elseif($user_auth['roleid']==7 || $user_auth['roleid']==11){
  		$data['place']=array('eq',$user_auth['place']);
  	}
    elseif($user_auth['roleid']==13){//江宁负责人
        $data['place|turncity']= '2';
    }
    elseif($user_auth['roleid']==14){//江北负责人
        $data['_string'] = "place=3 OR turncity=1";
    }
    if($parent){
        $data['bank_id'] = $parent;
    }
    if($child){
        $data['part_bank_id'] = $child;
    }
    if($send_start && $send_end){
        $data['audit_time'] = array(array('elt',$send_end) , array('egt',$send_start));
    }
    elseif($send_start && empty($send_end)){
        $data['audit_time'] = array('egt',$send_start);
    }
    elseif(empty($send_start) && $send_end){
        $data['audit_time'] = array('elt',$send_end);
    }
    if($money_start && $money_end){
        $data['credit_real_time'] = array(array('elt',$money_end) , array('egt',money_start));
    }
    elseif($money_start && empty($money_end)){
        $data['credit_real_time'] = array('egt',$money_start);
    }
    elseif(empty($money_start) && $money_end){
        $data['credit_real_time'] = array('elt',$money_end);
    }
    if($user_auth['roleid']==4  && $place){
      if($place==1){
        $data['_string'] = "place=1 and turncity=0";
      }
      if($place==2){
        //$data['place&turncity']=array('2','0','_multi'=>true);
        $data['_string'] = "place='1' and turncity='2' or place='2' ";
      }
      if($place==3){
        $data['_string'] = 'place=3 or place=1 and turncity=1';
      }
    }
    if($market){
        $user = D('User') -> findSameUser($market);
        $data['market_id'] = $user['user_id'];
    }
    if($sign){
        $user = D('User') -> findSameUser($sign);
        $data['sign_id'] = $user['user_id'];
    }
    if($supervise){
      $data['supervise']=$supervise;
    }
	  $data['isdel']='0';
    $docs1 = D('Document') -> selectData($data);
    foreach($docs1 as $k=>$v){
        $sumbusy +=getMoney($v['doc_id']);//商业贷款
        $sumaccount +=($v['amount']-getMoney($v['doc_id']));
    }
    $this->assign('sumbusy' , $sumbusy);
    $this->assign('sumaccount' , $sumaccount);
    $count=D('Document') -> countData($data);
    $n=15;
    $page=new \Think\Page($count,$n);
    foreach($where as $key=>$val) {
        $page->parameter[$key]   =   urlencode($val);
    }
    $show= $page->show();// 分页显示输出
    $this->assign('page',$show);
    $docs = D('Document') -> selectData($data,$p,$n);
    $this->assign('document' , $docs);
    $this->assign('docnum' , $count);
    $banks = session('USER_AUTH.banks');
    $roleid = session('USER_AUTH.roleid');
    $parents = D('Bank') -> selectBank(array('pid'=>'0','isdel'=>'0'));
    foreach(explode(',',$banks) as $k=>$v){
        $b = D('Bank')->findData($v);
        if($b['isdel']=='0' && $b['pid']=='0'){
            $parents[] = $b;
        }
    }
    $this->assign('parents' , $parents);
    $this->display('Static/index');
  }



    public function mortgage(){
      $this->display('Static/mortgage');
    }




    public function index1(){
     $user_auth = session('USER_AUTH');
     $parent = I('post.parent_bank');
     $child = I('post.child_bank');
     $money_start = I('post.money_start');
     $money_end = I('post.money_end');
     $money_start = timeStrop($money_start);
     $money_end = timeStrop($money_end);
     //echo $money_start;
     if($parent){
         $data['bank_id'] = $parent;
     }
     if($child){
         $data['part_bank_id'] = $child;
     }

     if($money_start && $money_end){
         $data['credit_time'] = array(array('elt',$money_end) , array('egt',$money_start));
     }
     elseif($money_start && empty($money_end)){
         $data['credit_time'] = array('egt',$money_start);
     }
     elseif(empty($money_start) && $money_end){
         $data['credit_time'] = array('elt',$money_end);
     }
     else{
         $where['credit_time'] = array('neq' , '');
     }
      if($_GET['p']==''){
        $p='1';
    }else{
        $p=$_GET['p'];
    }
    if($user_auth['roleid']==3){
	    if(!empty($user_auth['banks'])){
	        $data['bank_id'] = array('IN',$user_auth['banks']);
	    }
	}
	elseif($user_auth['roleid']==6 || $user_auth['roleid']==11){
		$data['place']=array('eq',$user_auth['place']);
	}
	$data['_string']='credit_real_time is null';
	$data['credit_time']=array('neq','');
	$data['isdel']='0';

    $count=D('Document') -> countData($data);

    $page=new \Think\Page($count,$n);
    foreach($data as $key=>$val) {
        $Page->parameter[$key]   =   urlencode($val);
    }
    $show= $page->show();// 分页显示输出
    $this->assign('page',$show);

      $docs = D('Document') -> selectData($data,$p,$n);

      $this->assign('document' , $docs);

      $this->assign('docnum' , $count);
      foreach($docs as $k=>$v){
            $sumacount +=D('Extend')->sumAccount(array('doc_id'=>$v['doc_id']));
        }
        foreach($docs as $kk=>$vv){
            $summoney += D('Extend')->sumMoney(array('doc_id'=>$vv['doc_id']));
        }
        $this->assign('summoney' , $summoney);
        $this->assign('sumacount' , $sumacount);
       $banks = session('USER_AUTH.banks');
        $roleid = session('USER_AUTH.roleid');
        if( haveAblitity('38' , $roleid) ){
            $parents = D('Bank') -> selectBank(array('pid'=>'0','isdel'=>'0'));
        }
        elseif(haveAblitity('39' , $roleid)){
            foreach(explode(',',$banks) as $k=>$v){
                $b = D('Bank')->findData($v);
                if($b['isdel']=='0' && $b['pid']=='0'){
                    $parents[] = $b;
                }
            }
        }

      $this->assign('parents' , $parents);
      $this->display('Static/index1');
    }


    public function zhi($id){
        $children = D('Bank') -> selectChildBank($id);
        exit(json_encode($children));
    }











}
